# -*- coding:utf-8 -*-

import urllib
import re


def jpg_char( ):
	#打开一级url
	url_1 = r'http://photo.ifeng.com/'
	url_1_html=urllib.urlopen(url_1)
	url_1_read=url_1_html.read().decode('utf-8')
	#搜索二级url
	url_char=r"'url':'(.*?shtml)'"
	url_2=re.findall(url_char,url_1_read,re.M)
	#print url_2
	#成功获取10条

	#获取一级url的首张图片
	re_jpg=r"'image':'(.*?jpg)'"
	re_1_jpg_url=re.findall(re_jpg,url_1_read)

	#获取标题
	re_title=r"'title':'(.*?)',"
	re_1_title_text=re.findall(re_title,url_1_read)
	url_1_dict={}
	for i in range(0,10):
		url_1_dict[re_1_title_text[i]]=re_1_jpg_url[i]
	#print url_1_dict
	#获取二级url下的图片
	#二级url下面的图片按照:url+#p=%d   %d是第几页
	#用:class="DB_total">5</span>检测总共有几页
	#储存页数
	url_2_dict={}
	a=[]
	url_2_title=r"title:'(.*?)'"
	url_2_jpg=r'big_img:(.*?\.jpg).*?'
	a.append(url_1_dict)
	o=0
	for l in url_2:
		url_2_html=urllib.urlopen(l)
		url_2_read=url_2_html.read().decode('utf-8')
		url_2_title_text=re.findall(url_2_title,url_2_read)#二级url页面标题
		url_2_jpg_url=re.findall(url_2_jpg,url_2_read)#二级url页面图片
		for i in range(len(url_2_title_text)/2-2):
			url_2_dict[url_2_title_text[i]]=url_2_jpg_url[i]
			a.append(url_2_dict)
		o+=1
		if o==10:
			break
	return a
